package leetcode.day_2021_03_8_2021_03_14;

import java.util.Arrays;

/**
 * 48. 旋转图像
 * https://leetcode-cn.com/problems/rotate-image/
 */
public class LeetCode0048 {

    public static void rotate(int[][] matrix) {
        int len = matrix.length;;
        for (int i=0; i<len; i++) {
            for (int j=0; j<=i; j++) {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = temp;
            }
        }
        for (int i=0; i<matrix.length; i++) {
            for (int j=0; j<matrix.length; j++) {
                System.out.print(matrix[i][j] + " ");
            }
            System.out.println();
        }

        for (int i=0; i<len; i++) {
            for (int j=0; j<len/2; j++) {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[i][len-1-j];
                matrix[i][len-1-j] = temp;
            }
        }
    }

    public static void main(String[] args) {
        // [[1,2,3],[4,5,6],[7,8,9]]
        int[][] matrix = new int[][] {
                {1,2,3,0},
                {4,5,6,0},
                {7,8,9,0},
                {10,11,12,0}
        };
        rotate(matrix);
       for (int i=0; i<matrix.length; i++) {
           for (int j=0; j<matrix.length; j++) {
               System.out.print(matrix[i][j] + " ");
           }
           System.out.println();
       }
    }
}
